<template>
	<view class="invoice">
		<!-- <view class="app-background-fixed"></view> -->
		<u-sticky bgColor="#fff">
			<view style="padding: 10rpx 0;">
				<u-tabs :list="list1" lineColor="#FD8F19" lineWidth="80rpx" :current="current" :scrollable="false"
					:is-scroll="false" @change="change"></u-tabs>
			</view>
		</u-sticky>

		<view class="cell app-pages">
			<view class="cell-item" :class="'box'+(current+1)" v-for="(item,index) in listData" :key="index">
				<view class="row1">
					<view class="row1-title"> {{Number(item.couponType)==1?('满减'+item.minMonetary+'元使用'):'直减'}}</view>
					<view class="row1-date">使用时间：{{item | filTime}}</view>
				</view>
				<view class="row3">
					<view class="row3-amount">{{item.couponValue}}<text>元</text></view>
					<view class="row3-text" @click="handleSubmit(item)">立即使用</view>
				</view>
			</view>
		</view>
		<!-- 	<view class="cell app-pages" v-show="current == 1">
			<view class="cell-item box2" v-for="item in 10" :key="item">
				<view class="row1">
					<view class="row1-title" style="color: #C1C1C1;">满500元使用</view>
					<view class="row1-date" style="color: #C1C1C1;">使用时间：2023年11.1-11.10</view>
				</view>
				<view class="row3">
					<view class="row3-amount" style="color: #C1C1C1;">100<text>元</text></view>
					<view class="row3-text" style="background-color: #C1C1C1;">立即使用</view>
				</view>
			</view>			
		</view>
		<view class="cell app-pages" v-show="current == 2">
			<view class="cell-item box2">
				<view class="row1">
					<view class="row1-title" style="color: #C1C1C1;">满500元使用</view>
					<view class="row1-date" style="color: #C1C1C1;">使用时间：2023年11.1-11.10</view>
				</view>
				<view class="row3">
					<view class="row3-amount" style="color: #C1C1C1;">100<text>元</text></view>
					<view class="row3-text" style="background-color: #C1C1C1;">立即使用</view>
				</view>
			</view>
		</view> -->

		<view style="height: 200rpx;"></view>
	</view>
</template>
<script>
	import {
		listMyCoupon
	} from "@/culturalCreativity/http/my.js";
	import {dateFormat} from "@/utils/pay.js";
	export default {
		data() {
			return {
				list1: [{
					name: '未使用',
				}, {
					name: '已使用',
				}, {
					name: '已失效'
				}],
				current: 0,
				listData: [],
				openid: uni.getStorageSync('openid'),
			}
		},
		onLoad() {
			this.change({index: 0})
		},
		methods: {
			handleRouter(url) {
				uni.navigateTo({
					url
				})
			},
			handleSubmit(options) {
				uni.navigateTo({
					url:"/culturalCreativity/common/shoppingDetails?id="+options.goodsId
				});
			},
			async change(e) {
				try {
					uni.showLoading({
						title: "加载中...",
						mask: true
					})
					this.current = e.index;
					let res = await listMyCoupon({
						userId: this.openid,
						isUse: e.index
					});
					this.listData = res.data.rows;
					uni.hideLoading();
				} catch (e) {
					console.error(`mySecurities文件夹下的index.vue 出错`, e)
					uni.hideLoading();
					//TODO handle the exception
				}
			}
		},
		filters:{
			filTime(options){
				let str1 = dateFormat('YYYY年m.d',new Date(options.validiteStart.replaceAll('-','/')));
				let str2 = dateFormat('m.d',new Date(options.validiteEnd.replaceAll('-','/')));
				return `${str1}-${str2}`;
			}
		}
	}
</script>
<style lang="scss" scoped>
	.invoice {
		.cell {
			background-color: #F7F7F7;

			.cell-item {
				display: flex;
				align-items: center;
				justify-content: space-around;
				box-shadow: 0px 0px 6px 4px rgba(0, 0, 0, 0.05);
				background-color: #FFFFFF;
				padding: 31rpx 24rpx;
				border-radius: 16rpx;
				margin-bottom: 24rpx;
				position: relative;

				.row1 {
					.row1-title {
						font-size: 50rpx;
						color: #1F1F1F;
						margin: 12rpx 0 12rpx 0;
					}

					.row1-date {
						font-size: 20rpx;
						color: #878787;
						border: 2rpx solid #EEEEEE;
						padding: 6rpx 10rpx;
					}
				}

				.row2 {
					width: 300rpx;

					.row2-title {
						height: 80rpx;
					}
				}

				.row3 {
					border-left: 2px dashed #EEEEEE;
					padding-left: 28rpx;

					.row3-amount {
						color: #4D84C9;
						font-size: 62rpx;
						text-align: center;
						text {
							font-size: 20rpx;
							margin-left: 5rpx;
						}
					}

					.row3-text {
						background-color: #4D84C9;
						color: #FFFFFF;
						padding: 4rpx 20rpx;
						font-size: 22rpx;
						border-radius: 16rpx;
					}

					.submit {
						font-size: 24rpx;
						background-color: #FFFFFF;
						border-radius: 15rpx;
						border: 2rpx solid #f74062;
						padding: 6rpx 40rpx;
						color: #f74062;
					}
				}
			}

			.box1 {
				background: linear-gradient(to bottom, #4D84C9 0%, #4D84C9 10%, #ffffff 0%, #ffffff 100%);
			}

			.box2,
			.box3 {
				background: linear-gradient(to bottom, #C1C1C1 0%, #C1C1C1 10%, #F7F7F7 0%, #F7F7F7 100%);

				.row1-title,
				.row1-date,
				.row3-amount {
					color: #C1C1C1 !important;
				}

				.row3-text {
					background-color: #C1C1C1 !important;
				}
			}
		}

	}
</style>
